package com.tarena.lbs.business.servcie.impl;

import com.tarena.lbs.business.dao.repository.BusinessCategoryRepository;
import com.tarena.lbs.business.pojo.po.BusinessCategoryPO;
import com.tarena.lbs.business.pojo.vo.BusinessCategoryVO;
import com.tarena.lbs.business.servcie.BusinessCategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class BusinessCategoryServiceImpl implements BusinessCategoryService {
    @Resource
    private BusinessCategoryRepository businessCategoryRepository;
    public List<BusinessCategoryVO> allCategories() {
        List<BusinessCategoryPO> pos = businessCategoryRepository.allCategories();
        return pos.stream().map(this::convertToVO).collect(Collectors.toList());
    }

    private BusinessCategoryVO convertToVO(BusinessCategoryPO po) {
        BusinessCategoryVO vo = new BusinessCategoryVO();
        BeanUtils.copyProperties(po, vo);
        return vo;
    }
}
